package com.appcenter.application.mapper;

import com.appcenter.application.input.User.GetDataUsersInput;
import com.appcenter.application.model.Users;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;

@Repository
@org.apache.ibatis.annotations.Mapper
public interface UsersMapper extends Mapper<Users> {

    @Select("select * from users where usercode=#{UserCode}")
    Users getUsersByUserCode(String UserCode);

    @Select("select * from users where usercode=#{UserCode} and Id <> #{Id}")
    Users getUsersByUserCodeNoId(@Param("UserCode") String UserCode, @Param("Id") String Id);


    @Select("select * from users where id = #{Id}")
    Users getUserById(String Id);

    @Select("select * from users where UserCode = #{UserCode}")
    Users getUserByUserCode(String UserCode);

    @Results({
            @Result(column = "PID", property = "UserAddress", one = @One(select = "com.appcenter.application.mapper.UserAddrsMapper.getUserAddsByUserId"))
    })
    @Select("<script>" +
            "select *,Id as PID from users where 1=1 " +
            "" +
            " <when test='keyword!=null'>" +
            " AND (UserCode like concat('%',#{keyword},'%') or UserName like concat('%',#{keyword},'%') or DingUserId like concat('%',#{keyword},'%'))" +
            " </when>" +
            "" +
            "</script>")
    List<Users> searchUsers(GetDataUsersInput input);


}
